package com.talkweb.newproject.admin.sysposition.service;

import com.talkweb.newproject.admin.sysposition.dao.SysPositionDao;
import com.talkweb.newproject.admin.sysposition.dto.SysPositionDTO;
import com.talkweb.newproject.api.model.admin.SysPositionParam;
import com.talkweb.newproject.common.web.annotation.Page;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by qsf on 2019/4/18.
 */
@Service
public class SysPositionService {
    @Autowired
    private SysPositionDao sysPositionDao;


    /**
     * 新增
     */
    @Transactional
    public Long inserSysPosition(SysPositionDTO sysPositionDTO) throws Exception {
        Map<String, Object> params = new HashMap();
        params.put("dto", sysPositionDTO);
        Integer count = sysPositionDao.inserSysPosition(params);
        SysPositionDTO result = (SysPositionDTO) params.get("dto");
        return result.getId();
    }

    /**
     * 更新职位信息
     */
    @Transactional(rollbackFor = {Exception.class})
    public void updateSysPosition(SysPositionDTO sysPositionDTO) throws Exception {
        Map<String, Object> params = new HashMap();
        params.put("dto", sysPositionDTO);
        sysPositionDao.updateSysPosition(sysPositionDTO);
    }

    /**
     * 根据主键删除职位信息
     */
    @Transactional(rollbackFor = {Exception.class})
    public void deleteSysPositionByPrimaryKey(String ids) throws Exception {
        Map<String, Object> params = new HashMap();
        params.put("ids", ids);
        sysPositionDao.deleteSysPositionByPrimaryKey(params);
    }

    /**
     * 根据主键查询职位信息
     */
    public SysPositionDTO querySysPositionByPrimaryKey(String id) throws Exception {
        SysPositionDTO dto = sysPositionDao.querySysPositionByPrimaryKey(id);
        if (dto == null) dto = new SysPositionDTO();
        return dto;
    }

    public SysPositionDTO queryLikeSysPostion(SysPositionDTO obj) throws Exception {
        Map<String, Object> params = new HashMap();
        params.put("dto", obj);

        return sysPositionDao.queryLikeSysPosition(params);
    }

    @Page
    public Object searchSysPosition(SysPositionParam obj) throws Exception {
        Map<String,Object> params = new HashedMap();
        params.put("dto",obj);
        return sysPositionDao.searchSysPosition(params);
    }
}
